import goodStorage from 'good-storage'
import { AxiosResponse } from 'axios'
import { Dicom } from '@/hooks/useSearchFormHooks'
import { Ref, ref } from 'vue'
import diocmApi from '@/api/diocmApi'
import { showNotify } from 'vant'
import router from '@/router'

class UseDiocmHooks {
  static useDiocmHooks = new UseDiocmHooks()
  dicomInfo: Ref<Dicom | null> = ref(null)
  async findDiocmView(id: string, moduleName: string) {
    const res: AxiosResponse<Dicom> = await diocmApi.findDiocmView(
      id,
      moduleName
    )
    const data = res.data
    goodStorage.set('dicom', data)
    if ((UseDiocmHooks.useDiocmHooks.dicomInfo.value = res.data)) {
      router.push({ path: '/dicom' })
    } else {
      showNotify({ type: 'warning', message: '该病人没有影像' })
    }
  }
}

export default UseDiocmHooks.useDiocmHooks
